package com.zyht.bank.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zyht.common.BaseServiceImpl;
import com.zyht.common.excel.IPersist;
import com.zyht.common.BaseDao;
import com.github.pagehelper.PageHelper;
import com.zyht.bank.dao.AxdCustLoanSQLMapper;
import com.zyht.bank.dao.AxdOrgInfoMapper;
import com.zyht.bank.dao.AxdOrgInfoSQLMapper;
import com.zyht.bank.entity.AxdOrgInfo;
import com.zyht.bank.entity.AxdOrgInfoExample;
import com.zyht.bank.manage.dao.AxdQrcodeMapper;
import com.zyht.bank.manage.entity.AxdQrcode;
import com.zyht.bank.manage.entity.AxdQrcodeExample;
import com.zyht.bank.manage.vo.OrgCodeVo;
import com.zyht.bank.service.AxdOrgInfoService;

@Service("axdOrgInfoService")
public class AxdOrgInfoServiceImpl extends BaseServiceImpl<AxdOrgInfo, AxdOrgInfoExample>
		implements AxdOrgInfoService, IPersist<AxdOrgInfo> {

	@Resource
	private AxdOrgInfoMapper axdOrgInfoMapper;

	@Resource
	private AxdOrgInfoSQLMapper axdOrgInfoSQLMapper;

	@Resource
	private AxdQrcodeMapper axdQrcodeMapper;
	
	@Resource
	private AxdCustLoanSQLMapper axdCustLoanSQLMapper;

	@Override
	public BaseDao<AxdOrgInfo, AxdOrgInfoExample> dao() {

		return axdOrgInfoMapper;
	}

	@Override
	public void deleteOrgAndQcode(Integer orgInfoId) {
		axdOrgInfoMapper.deleteByPrimaryKey(orgInfoId);
		AxdQrcodeExample example = new AxdQrcodeExample();
		example.createCriteria().andOrgIdEqualTo(orgInfoId);
		PageHelper.startPage(1, 1);
		List<AxdQrcode> axdQrcodes = axdQrcodeMapper.selectByExample(example);
		if (axdQrcodes.size() > 0) {
			axdQrcodeMapper.deleteByPrimaryKey(axdQrcodes.get(0).getQrcodeId());
		}

	}

	@Override
	public Integer doPersist(List<AxdOrgInfo> list) {
		return axdOrgInfoSQLMapper.addList(list);
	}

	@Override
	public List<AxdOrgInfo> selectByMap(Map<String, Object> map) {
		return axdOrgInfoSQLMapper.selectByMap(map);
	}

	@Override
	public List<String> getOrgCodes(String pcode) {
		return axdOrgInfoSQLMapper.getOrgCodes(pcode);
	}

	@Override
	public OrgCodeVo findOneByOrgCode(String orgCode) {
		return this.axdCustLoanSQLMapper.findOneByOrgCode(orgCode);
	}

	@Override
	public List<String> findOrgCodes(String pcode) {
		return this.axdCustLoanSQLMapper.findOrgCodes(pcode);
	}

}
